import { PureComponent } from 'react';
import moment from 'moment';
import '@/assets/iconfont/iconfont';
import styles from './StaffInfoList.less';
import SelectDeptTree from '@/components/SelectDeptTree';
import { dicTextByCodePcode,dicListByPcode } from '@/utils/dictionary'
import {
    Row,
    Col,
    Form,
    Input,
    Select,
    Modal,
    DatePicker,
    Button,
    Upload,
    Cascader
} from 'antd';
const FormItem = Form.Item;
const { Option } = Select;
const formItemLayout = {
 	labelCol: { span: 10 },
   	wrapperCol: { span: 14 },
};

@Form.create()
class UpdateForm extends PureComponent {

	constructor(props) {
		super(props);
		// const staffAge = moment().format('YYYY') - moment(props.values.date_of_birth).format('YYYY');
    this.state = {
			formVals: {
        za0100: props.values.za0100,
        id: props.values.id,
        a1501: props.values.a1501,
        a1504: props.values.a1504,
        a1507: props.values.a1507,
        a1511: props.values.a1511,
        a1514_1: props.values.a1514_1,
        a1514_2: props.values.a1514_2,
        a1517: props.values.a1517,
        a1519: props.values.a1519,
        a1521: props.values.a1521,
        a1524: props.values.a1524,
        a1527: props.values.a1527,
        a1529: props.values.a1529,
        a1531: props.values.a1531,
        a1534: props.values.a1534,
        a1537: props.values.a1537,
        a1544: props.values.a1544,
        a1546: props.values.a1546,
        a1547: props.values.a1547,
        a1548: props.values.a1548,
        a1514: props.values.a1514,
        a1567: props.values.a1567,
        a1570: props.values.a1570,
        a1571: props.values.a1571,
        a1572: props.values.a1572,
        a1573: props.values.a1573

			},
			getDeptTreeBySelectTree: "",
		};

	}


	componentWillReceiveProps(nextProps) {
		// if(undefined != nextProps.values && nextProps.values !== this.props.values) {
		// 	const staffAge = moment().format('YYYY') - moment(nextProps.values.date_of_birth).format('YYYY');
		//     this.setState({
		//       formVals: nextProps.values,
		//       imageUrl: nextProps.values.photo_sign,
		//       photoNum: nextProps.values.photo_sign?1:0,
		//       ageNum: staffAge?staffAge:null
		//     });
		// }

	}

	selectedDeptTreeValue = (deptRecord) => {
		this.setState({
			getDeptTreeBySelectTree: deptRecord
		})
	}



 	birthChange = value => {
		this.setState({
			ageNum: moment().format('YYYY') - value.format('YYYY')

		})
	}

	handleLocalUpdate = (event) => {
		event.preventDefault();
		const { form,handleSubmitSubsetInfo } = this.props;
		const { formVals: oldValue,getDeptTreeBySelectTree } = this.state;
		form.validateFields((err, fieldsValue) => {
			if(err) return;
			form.resetFields();
			const formVals = {
				...oldValue,
				...fieldsValue
			};
			this.setState({
				formVals,
			});

			/* if(getDeptTreeBySelectTree) {
				formVals.dept_id = getDeptTreeBySelectTree.triggerNode.props.dataRef.dept_id;
				formVals.dept = getDeptTreeBySelectTree.triggerNode.props.dataRef.title;
			}

			if(formVals.post) {
				formVals.post_id = formVals.post.key;
				formVals.post_name = formVals.post.label;
			}
*/
			if(formVals.a1507) {
      			formVals.a1507 = moment(formVals.a1507._d).format("YYYY-MM-DD");
      		}
			if(formVals.a1511) {
      			formVals.a1511 = moment(formVals.a1511._d).format("YYYY-MM-DD");
      		}
			// formVals.file = this.state.file;
			handleSubmitSubsetInfo(formVals,"update_for_staff_trainInfo");

		});
	};

  render() {
    const {
    	form: {getFieldDecorator},
    	falg,
      spinIndex,
    	cancelEditJobInfo,
    	cascaderList,
    	values,
    	selectDeptTree,
    	postForUser,
      requestModelName,
      dispatch
    } = this.props;

    const parentDeptTreeMethod = {
		dispatch: dispatch,
		selectDeptTree: selectDeptTree,
		selectedDeptTreeValue: this.selectedDeptTreeValue,
		requestModelName: requestModelName,
	}

    const { formVals,imageUrl,photoNum } = this.state;
    // 多选处理 TODO
    let newPlace = [];
    if(values.place_of_origin && values.place_of_origin != "null" ) {
    	const place = JSON.parse(values.place_of_origin);
    	newPlace = place.map((item,index) => item = item + '');
    }
	return (
		<div>
			{falg?(
				<Form  onSubmit={this.handleLocalUpdate}>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="培训班名称">
			              {getFieldDecorator('a1531', {
			              rules: [{ required: true, message: '请输入1-10个字符',max: 10}],
			              initialValue: formVals.a1531,
			              })(<Input placeholder="1-10个字符"/>)}
			          </FormItem>
			        </Col>

              <Col md={12} sm={24}>
                <FormItem  label="培训班类别">
                    {getFieldDecorator('a1534', {
                      rules: [{ required: false, message: '请选择'}],
                      initialValue: formVals.a1534,
                    })(
                      <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                      	{dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
                      		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                      	}):null}
                      </Select>
                    )}
                </FormItem>
              </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="培训完成情况">
			              {getFieldDecorator('a1544',{
			              	initialValue: formVals.a1544,
			              })(
			              	<Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
			              		{dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
			              			return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
			              		}):null}
			              	</Select>
			              )}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="培训时所在单位及职务">
			              {getFieldDecorator('a1546', {
			              rules: [{ required: false, message: '1-40个字符'}],
			              initialValue: formVals.a1546,
			              })(<Input placeholder="1-40个字符" />)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

					<Col md={12} sm={24}>
			          <FormItem  label="承训机构名称">
			              {getFieldDecorator('a1519', {
			              rules: [{ required: false, message: '请选择'}],
			              initialValue: formVals.a1519,
			              })(
			              	<Input placeholder="1-40个字符" />
			              )}
			          </FormItem>
			        </Col>

			        <Col md={12} sm={24}>
			          <FormItem  label="培训地点">
			              {getFieldDecorator('a1521',{
			                rules: [{ required: false, message: '请选择！'}],
                      initialValue: formVals.a1521,
			              })(
			              	<Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                        {dicListByPcode('R1') != undefined?dicListByPcode('R1').map((item,index) => {
                          return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                        }):null}
                      </Select>
			              )}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


			        <Col md={12} sm={24}>
			          <FormItem  label="培训主办单位名称">
			              {getFieldDecorator('a1514_1', {
			              rules: [{ required: false, message: '1-40个字符'}],
			              initialValue: formVals.a1514_1,
			              })(
                      <Input placeholder="1-40个字符" />
                    )}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="主办单位机构代码">
			              {getFieldDecorator('a1514_2', {
                    rules: [{ required: false, message: '1-40个字符'}],
			              initialValue: formVals.a1514_2,
			              })(<Input placeholder="1-40个字符" />)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


			        <Col md={12} sm={24}>
			          <FormItem  label="主办单位级别">
			              {getFieldDecorator('a1517',{
			                    rules: [{ required: false, message: '请选择！'}],
			                    initialValue: formVals.a1517,
			                  })(
			                  	<Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
			                      {dicListByPcode('R1') != undefined?dicListByPcode('R1').map((item,index) => {
			                        return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
			                      }):null}
			                    </Select>
			                  )}
			              </FormItem>
			        </Col>

			       	<Col  md={12} sm={24}>
			       	  <FormItem  label="开始日期">
			       	      {getFieldDecorator('a1507', {
			       	        rules: [{ required: false, message: '请选择'}],
                      initialValue: formVals.a1507?moment(formVals.a1507):null,
                      })(
                      <DatePicker  format="YYYY-MM-DD" style={{ width: '100%' }} placeholder="请选择"/>
                      )}
                    </FormItem>
			       	</Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			    	<Col md={12} sm={24}>
			    	  <FormItem  label="结束日期">
			    	      {getFieldDecorator('a1511', {
			    	        rules: [{ required: false, message: '请选择'}],
			    	        initialValue: formVals.a1511?moment(formVals.a1511):null,
			    	        })(
			    	        <DatePicker  format="YYYY-MM-DD" style={{ width: '100%' }} placeholder="请选择"/>
			    	        )}
			    	  </FormItem>
			    	</Col>

            <Col md={12} sm={24}>
              <FormItem  label="培训离岗状态">
                  {getFieldDecorator('a1504', {
                    rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a1504,
                    })(
                    <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                    	{dicListByPcode('JK') != undefined?dicListByPcode('JK').map((item,index) => {
                    		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                    	}):null}
                    </Select>
                  )}
              </FormItem>
            </Col>
			    </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


              <Col md={12} sm={24}>
                <FormItem  label="培训证书编号">
                    {getFieldDecorator('a1529', {
                    rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a1529,
                    })(
                      <Input placeholder="1-40个字符" />
                    )}
                </FormItem>
              </Col>
              <Col md={12} sm={24}>
                <FormItem  label="免训原因">
                    {getFieldDecorator('a1548', {
                    rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a1548,
                    })(<Input placeholder="1-40个字符" />)}
                </FormItem>
              </Col>

          </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


              <Col md={12} sm={24}>
                <FormItem  label="免训标识">
                    {getFieldDecorator('a1547', {
                    rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a1547,
                    })(
                      <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                      	{dicListByPcode('JK') != undefined?dicListByPcode('JK').map((item,index) => {
                      		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                      	}):null}
                      </Select>
                    )}
                </FormItem>
              </Col>


          </Row>


				<Row gutter={{ md: 8, lg: 24, xl: 48 }}>
					<Col md={12} sm={24}>
				        <Button
				        	size="large"
				        	style={{marginRight: '10px'}}
				        	onClick={()=> {
				        		const { form } = this.props;
								form.resetFields();
				        		cancelEditJobInfo(spinIndex);
				        	}}>
				        	取消
				       	</Button>
				        <Button size="large" type="primary" htmlType="submit">保存</Button>
				    </Col>
				</Row>

			  </Form>
			):(
			<Form  {...formItemLayout}>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="培训班名称">
			              {getFieldDecorator('a1531')(<span>{formVals.a1531}</span>)}
			          </FormItem>
			        </Col>

					<Col md={12} sm={24}>
			          <FormItem  label="培训班类别">
			              {getFieldDecorator('a1534')(<span>{formVals.a1534}</span>)}
			          </FormItem>
			        </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="培训完成情况">
			              {getFieldDecorator('a1544')(<span>
			              	{(() => {
			              		return dicTextByCodePcode(formVals.a1544, 'AX');
				              	}
			             )()}
			            </span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="培训时所在单位及职务">
			              {getFieldDecorator('a1546')(<span>{formVals.a1546}</span>)}
			            </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

					<Col md={12} sm={24}>
			          <FormItem  label="承训机构名称">
			              {getFieldDecorator('a1519')(<span>{formVals.a1519}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="培训地点">
			              {getFieldDecorator('a1521')(<span>{formVals.a1521}
			              	</span>)}
			          </FormItem>
			        </Col>


			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="培训主办单位名称">
			              {getFieldDecorator('a1514_1')(<span>{formVals.a1514_1}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="主办单位机构代码">
			              {getFieldDecorator('a1514_2')(<span>{formVals.a1514_2}</span>)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="主办单位级别">
			              {getFieldDecorator('a1517')(<span>{formVals.a1517}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="开始日期">
			            {getFieldDecorator('a1507')(<span>{formVals.a1507?moment(formVals.a1507).format('YYYY-MM-DD'):null}</span>)}
			          </FormItem>
			        </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			    	<Col  md={12} sm={24}>
				        <FormItem  label="结束日期">
				          {getFieldDecorator('a1511')(<span>{formVals.a1511?moment(formVals.a1511).format('YYYY-MM-DD'):null}</span>)}
				        </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="培训离岗状态">
			              {getFieldDecorator('a1504')(<span>{formVals.a1504}
			              </span>)}
			          </FormItem>
			        </Col>

			    </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

          	<Col  md={12} sm={24}>
                <FormItem  label="培训证书编号">
                  {getFieldDecorator('a1504')(<span>{formVals.a1504}</span>)}
                </FormItem>
              </Col>
              <Col md={12} sm={24}>
                <FormItem  label="免训原因">
                    {getFieldDecorator('a1548')(<span>{formVals.a1548}
                    </span>)}
                </FormItem>
              </Col>

          </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

              <Col md={12} sm={24}>
                <FormItem  label="免训标识">
                    {getFieldDecorator('a1547')(<span>{formVals.a1547}
                    </span>)}
                </FormItem>
              </Col>

          </Row>
			  </Form>
			)}
		</div>


	);
  }

}

export default UpdateForm;
